package net.seabookchen.dao;

import java.util.List;

import net.seabookchen.pojo.BlogComment;
import net.seabookchen.pojo.BlogPost;

import com.googlecode.objectify.ObjectifyService;
import com.googlecode.objectify.Query;

public class BlogCommentDao extends ObjectifyGenericDao<BlogComment> {
	
	static {
		ObjectifyService.register(BlogComment.class);
	}

	public BlogCommentDao(Class<BlogComment> clazz) {
		super(clazz); 
	}
	
	public List<BlogComment> listLatestComments(int number) {
		Query<BlogComment> comments = ofy().query(BlogComment.class).order("-modifiedDate").limit(number);
		return deadOrLive(comments);
	}
	
	public List<BlogComment> listLatestComments() {
		Query<BlogComment> comments = ofy().query(BlogComment.class).order("modifiedDate");
		return deadOrLive(comments);
	}
	
	public List<BlogComment> getAllCommentsByPost(BlogPost post) {
		Query<BlogComment> comments = ofy().query(BlogComment.class).filter(
				"post", post);
		
		return deadOrLive(comments);
	}
}
